package kr.saeildadim.androidexam_saeildamil.chapter6;

import kr.saeildadim.androidexam_saeildamil.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;

public class SetparameterEx extends Activity {
	Button mLeft;
	Button mRight;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setparameter);
		
		mLeft = (Button) findViewById(R.id.setparameter_left);
		mRight= (Button) findViewById(R.id.setparameter_right);
		
		mLeft.setOnClickListener(listener);
		mRight.setOnClickListener(listener);
	}
	View.OnClickListener listener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			if(v.getId()==R.id.setparameter_left){
				setParam(1,3);
			}else{
				setParam(3,1);
			}
			
		}

		
	};
	private void setParam(int left, int right) {
		LinearLayout.LayoutParams lparam = (LayoutParams) mLeft.getLayoutParams();
		LinearLayout.LayoutParams rparam = (LayoutParams) mRight.getLayoutParams();
		
		String str = "왼쪽 버튼  weight="+lparam.weight+"오른쪽버튼 weight="+rparam.weight;
		Toast.makeText(this,str , Toast.LENGTH_LONG).show();
		
		lparam.weight= left;
		rparam.weight= right;
		
		mLeft.setLayoutParams(lparam);
		mRight.setLayoutParams(rparam);
		
	};
}
